package com.song.day01protobuf编码解码.client;

import com.song.day01protobuf编码解码.PackageMessageProto;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
//SimpleChannelInboundHandler<PackageMessage>
public class ClientHandler extends ChannelInboundHandlerAdapter {

//	public BlockingQueue<PackageMessage> queue = new LinkedBlockingQueue<PackageMessage>();
//	
//	
//	public PackageMessage readMsg() {
//		return this.queue.poll();
//	}
//	
//	public boolean isEmpQueue()
//	{
//		return CollectionUtils.isEmpty(queue);
//	}
	
//	@Override
//	public void channelActive(ChannelHandlerContext ctx) throws Exception {
//
//		PackageMessageProto.PackageMessage.Builder builder =  PackageMessageProto.PackageMessage.newBuilder();
//		builder.setAge(23);
//		builder.setId(1);
//		builder.setName("song");
//		PackageMessageProto.PackageMessage msg = builder.build();
//		ctx.writeAndFlush(msg);
//	}

	public void channelRead(ChannelHandlerContext ctx, Object obj)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("客户端接受数据 "+obj);
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		// TODO Auto-generated method stub
		cause.printStackTrace();
		ctx.close();
	}

	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		// TODO Auto-generated method stub
		ctx.flush();
		ctx.close();
		System.out.println("客户端接受数据结束");
	}

	

}
